//src/utils/request.js
import axios, {AxiosRequestConfig, AxiosResponse, AxiosError} from 'axios'

// 创建 axios 实例
// console.log(process.env.VUE_APP_BASE_API)
const request = axios.create({
  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
  timeout: 10000, // request timeout
})

//  请求拦截器
request.interceptors.request.use(
  (config: AxiosRequestConfig) => {
    // console.log(config)
    return config
  },
  (error: AxiosError) => {
    return Promise.reject(error)
  }
)

// 响应拦截器
request.interceptors.response.use(
  (response: AxiosResponse) => {
    return response
  },
  (error: AxiosError) => {
    //响应错误
    return Promise.reject(error)
  }
)

export default request